2020-2021 Sunseeker Telemetry and Lighting System
eusci_a_uart_ex1_loopbackAdvanced.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
61 //******************************************************************************
62 #include "driverlib.h"
63 
64 uint16_t i;
65 uint8_t RXData = 0, TXData = 0;
66 uint8_t check = 0;
67 
68 void main(void)
69 {
70  // stop watchdog
71  WDT_A_hold(WDT_A_BASE);
72 
73  // LFXT Setup
74  //Set PJ.4 and PJ.5 as Primary Module Function Input.
75  /*
76 
77  * Select Port J
78  * Set Pin 4, 5 to input Primary Module Function, LFXT.
79  */
80  GPIO_setAsPeripheralModuleFunctionInputPin(
81  GPIO_PORT_PJ,
82  GPIO_PIN4 + GPIO_PIN5,
83  GPIO_PRIMARY_MODULE_FUNCTION
84  );
85 
86  //Set DCO frequency to 8 MHz
87  CS_setDCOFreq(CS_DCORSEL_1,CS_DCOFSEL_3);
88  //Set external clock frequency to 32.768 KHz
89  CS_setExternalClockSource(32768,0);
90  //Set ACLK=XT1
91  CS_initClockSignal(CS_ACLK,CS_XT1CLK_SELECT,CS_CLOCK_DIVIDER_1);
92  //Start XT1 with no time out
93  CS_turnOnXT1(CS_XT1_DRIVE_0);
94  //Set SMCLK = DCO with frequency divider of 8
95  CS_initClockSignal(CS_SMCLK,CS_DCOCLK_SELECT,CS_CLOCK_DIVIDER_8);
96  //Set MCLK = DCO with frequency divider of 8
97  CS_initClockSignal(CS_MCLK,CS_DCOCLK_SELECT,CS_CLOCK_DIVIDER_8);
98 
99  // Configure UART pins
100  //Set P2.0 and P2.1 as Secondary Module Function Input.
101  /*
102 
103  * Select Port 2d
104  * Set Pin 0, 1 to input Secondary Module Function, (UCA0TXD/UCA0SIMO, UCA0RXD/UCA0SOMI).
105  */
106  GPIO_setAsPeripheralModuleFunctionInputPin(
107  GPIO_PORT_P2,
108  GPIO_PIN0 + GPIO_PIN1,
109  GPIO_SECONDARY_MODULE_FUNCTION
110  );
111 
112  // Configure UART
113  EUSCI_A_UART_initParam param = {0};
114  param.selectClockSource = EUSCI_A_UART_CLOCKSOURCE_ACLK;
115  param.clockPrescalar = 3;
116  param.firstModReg = 0;
117  param.secondModReg = 92;
118  param.parity = EUSCI_A_UART_NO_PARITY;
119  param.msborLsbFirst = EUSCI_A_UART_LSB_FIRST;
120  param.numberofStopBits = EUSCI_A_UART_ONE_STOP_BIT;
121  param.uartMode = EUSCI_A_UART_MODE;
122  param.overSampling = EUSCI_A_UART_LOW_FREQUENCY_BAUDRATE_GENERATION;
123 
124  if (STATUS_FAIL == EUSCI_A_UART_init(EUSCI_A0_BASE, &param)) {
125  return;
126  }
127 
128  EUSCI_A_UART_enable(EUSCI_A0_BASE);
129 
130  EUSCI_A_UART_clearInterrupt(EUSCI_A0_BASE,
131  EUSCI_A_UART_RECEIVE_INTERRUPT);
132 
133  // Enable USCI_A0 RX interrupt
134  EUSCI_A_UART_enableInterrupt(EUSCI_A0_BASE,
135  EUSCI_A_UART_RECEIVE_INTERRUPT); // Enable interrupt
136 
137  __enable_interrupt();
138  while (1)
139  {
140  TXData = TXData+1; // Increment TX data
141  // Load data onto buffer
142  EUSCI_A_UART_transmitData(EUSCI_A0_BASE,
143  TXData);
144  while(check != 1);
145  check = 0;
146  }
147 }
148 //******************************************************************************
149 //
150 //This is the USCI_A0 interrupt vector service routine.
151 //
152 //******************************************************************************
153 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
154 #pragma vector=USCI_A0_VECTOR
155 __interrupt
156 #elif defined(__GNUC__)
157 __attribute__((interrupt(USCI_A0_VECTOR)))
158 #endif
159 void EUSCI_A0_ISR(void)
160 {
161  switch(__even_in_range(UCA0IV,USCI_UART_UCTXCPTIFG))
162  {
163  case USCI_NONE: break;
164  case USCI_UART_UCRXIFG:
165  RXData = EUSCI_A_UART_receiveData(EUSCI_A0_BASE);
166  if(!(RXData == TXData)) // Check value
167  {
168  while(1);
169  }
170  check =1;
171  break;
172  case USCI_UART_UCTXIFG: break;
173  case USCI_UART_UCSTTIFG: break;
174  case USCI_UART_UCTXCPTIFG: break;
175  }
176 }
void EUSCI_A0_ISR(void)
MPU_initThreeSegmentsParam param
#define STATUS_FAIL
Definition: hw_memmap.h:23